/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uncopt.ohos.widget.text.justify.utils;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;

public class PreferenceUtils {
    public final static String PREFERENCE_FILE_NAME = "guidanceChart";

    /**
     * 保存数据
     *
     * @param context context
     * @param key key
     * @param value value
     */
    public static void putGuidanceChart(Context context, String key, boolean value) {
        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(PREFERENCE_FILE_NAME);
        preferences.putBoolean(key, value);
        preferences.flushSync();
    }

    /**
     * 获取数据
     *
     * @param context context
     * @param key key
     * @return 获取保存值
     */
    public static boolean getGuidanceChart(Context context, String key) {
        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(PREFERENCE_FILE_NAME);
        boolean value = preferences.getBoolean(key, false);
        return value;
    }
}
